# 2024/2/4 20:19 HFL
import re

import requests


def login(session):
    url = 'http://39.107.225.142/verydows/user/login.html?step=submit'
    data = {
        'username': 'aaa123',
        'password': '200c6d94e583e62c6964de3acdc723e5'
    }
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    return session.post(url, data, headers=headers)

def index_login(session):
    # url = 'http://39.107.225.142/verydows/index.php?m=backend'
    # response = session.get(url=url)
    # data1 = re.findall('type="hidden" name="(.*?)"', response.text)
    # data2 = re.findall('value="(.*?)"', response.text)
    # print(data1[0], data2[1])
    # return data1[0], data2[1]
    url = 'http://39.107.225.142/verydows/index.php?m=backend'
    url2 = 'http://39.107.225.142/verydows/index.php?m=backend&c=main&a=login'
    res = session.get(url=url)
    data1 = re.findall('type="hidden" name="(.*?)"', res.text)
    data2 = re.findall('value="(.*?)"', res.text)
    data = {
        data1[0]: data2[1],
        'username': 'admin',
        'password': '091bfa87c505bba664b431baf83cbc19'
    }
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    response = session.post(url=url2, data=data, headers=headers)
    print(response.text)
    print(data1, data2)
    return response



if __name__ == '__main__':

    data = index_login(requests.session())
    print(data)